﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace ERPStore.ProductRating.Controllers
{
	public class RatingController : ERPStore.Web.Controllers.StoreController
	{
		public ActionResult ShowRating(string viewName, string productCode)
		{
			var path = GlobalConfiguration.Configuration.Settings.PhysicalPath;
			if (path == null)
			{
				return new EmptyResult();
			}
			var fileName = string.Format("{0}\\app_data\\productrating\\{1}.xml", GlobalConfiguration.Configuration.Settings.PhysicalPath.TrimEnd('\\'), productCode);
			Models.ProductRate pr = null;

			if (System.IO.File.Exists(fileName))
			{
				var serializer = new System.Runtime.Serialization.DataContractSerializer(typeof(Models.ProductRate));
				using (var reader = System.IO.File.OpenRead(fileName))
				{
					pr = serializer.ReadObject(reader) as Models.ProductRate;
				}
			}
			else
			{
				pr = new Models.ProductRate();
			}

			ViewBag.ProductCode = productCode;
			return PartialView(viewName, pr);
		}
	}
}
